package com.aegis.manage.controller.gateway;

import com.aegis.common.mybatis.base.BaseController;
import com.aegis.common.mybatis.model.PageResult;
import com.aegis.manage.api.request.*;
import com.aegis.manage.api.vo.AppDetailVO;
import com.aegis.manage.api.vo.AppGroupVO;
import com.aegis.manage.api.vo.AppInfoVO;
import com.aegis.manage.api.vo.GenerateAppVO;
import com.aegis.manage.service.auth.app.AuthAppService;
import io.swagger.annotations.Api;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * @Author wuweixin
 *
 * @Version 1.0
 * @Descritube
 */
@RestController
@RequestMapping("/gateway/app")
@Api(tags = "网关-应用管理")
public class GatewayAppController extends BaseController<AuthAppService> {


    /**
     * 查询应用分页
     *
     * @param request
     * @return
     */
    @GetMapping("/page")
    public PageResult<AppInfoVO> queryAppPage(@Validated QueryAppInfoPageRequest request) {
        return getService().queryAppInfoPage(request);
    }

    /**
     * 创建应用
     *
     * @param request
     * @return
     */
    @PostMapping("/generate")
    public GenerateAppVO generateApp(@RequestBody @Validated GenerateAppRequest request) {
        return getService().generateApp(request);
    }

    /**
     * 查询应用详情
     *
     * @param id
     * @return
     */
    @GetMapping("/detail")
    public AppDetailVO queryDetail(@RequestParam("id") String id) {
        return getService().selectAppDetailById(id);
    }


    /**
     * 更新应用
     *
     * @param request
     */
    @PutMapping("/update")
    public void updateApp(@RequestBody @Validated UpdateAppRequest request) {
        getService().updateApp(request);
    }

    /**
     * 删除应用
     *
     * @param id
     */
    @DeleteMapping("/del")
    public void delApp(@RequestParam("id") String id) {
        getService().delAppById(id);
    }


    /**
     * @param request
     * @return
     */
    @GetMapping("/group/page")
    public PageResult<AppGroupVO> queryAppGroupPage(@Validated QueryAppGroupPageRequest request) {
        return getService().queryAppGroupPage(request);
    }

    /**
     * @param request
     */
    @PostMapping("/bindAppGroup")
    public void bindAppGroup(@RequestBody @Validated BindAppGroupRequest request) {
        getService().bindAppGroup(request);
    }


    /**
     * 删除权限组
     * @param id
     */
    @DeleteMapping("/group/del")
    public void delBindGroup(@RequestParam String id) {
        getService().delBindGroup(id);
    }
}
